package com.utils.parsetxt.file;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class findFilePathUtils {
	private final Log logger = LogFactory.getLog(getClass());
	public int weeks() {
		//获取当前日期是星期几
		Calendar c = Calendar.getInstance(); 
		c.setTime(new Date());  
		int  dayForWeek = 0 ;  
		if (c.get(Calendar.DAY_OF_WEEK) == 1 ){  
			dayForWeek = 7 ;  
		}else {  
			dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1 ;  
		}  
		logger.info("今天是星期："+dayForWeek);
		return dayForWeek;
	}
	
	/**
	 * 查找压缩zip文件路径
	 * @param filename
	 * @return ArrayList 路径集合
	 * @throws IOException
	 */
	@SuppressWarnings("unchecked")
	public ArrayList<String> findFilePath(String pathName,List<String> path) throws IOException {
			
		//查找传输文件 
		File file=new File(pathName);
		String files[]= file.list();
		if(file.isDirectory()){
//			logger.info("文件个数为："+files.length);
			for(int i=0;i<files.length;i++){
//				logger.info("文件名称为："+pathName+"//"+files[i]);
				//文件解析不区分每天和周末  统一修改为全量更新 0902 start
				//if(dayForWeek!=6&&("DUALUSE".equals(files[i].toUpperCase())||"EDD".equals(files[i].toUpperCase())||"PEP".equals(files[i].toUpperCase()))){
				//	logger.info("不是周六不解析！");
    		//	}else{
    		//		findFilePath(pathName+"//"+files[i],path);
    		//	}
    			//文件解析不区分每天和周末  统一修改为全量更新 0902 start end
					findFilePath(pathName+"//"+files[i],path);
			}
    	}else {
    		String fileName = file.getName().toUpperCase();
    		if(fileName.endsWith(".ZIP")){
    			logger.info("查找到的zip文件路径=>"+pathName);
    			path.add(pathName);
    		}
    	}
		return (ArrayList) path;
	}
	
	/**
	 * 查找txt文件路径
	 * @param filename
	 * @return ArrayList 路径集合
	 * @throws IOException
	 */
	@SuppressWarnings("unchecked")
	public ArrayList<String> transFile(String pathName,List<String> path) throws IOException {
		
		File file=new File(pathName);
		String files[]= file.list();
		if(file.isDirectory()){
			for(int i=0;i<files.length;i++){
				transFile(pathName+"//"+files[i],path);
			}
    	}else {
    		String fileName = file.getName().toUpperCase();
    		if("ENTITY.XML".equals(fileName)||"EXTRACTSUMMARY.TXT".equals(fileName)||"GROUP.XML".equals(fileName)){
    			logger.info("查找到需要传输的txt、xml文件名称=>"+pathName);
    			path.add(pathName);
    		}
    	}
		return (ArrayList) path;
	}
	
	public static void main(String[] args) throws IOException {
		findFilePathUtils ffd = new findFilePathUtils();
		List<String> fpath = new ArrayList<String>();
	//	ArrayList<String> Filepaths = ffd.transFile("E://Workspaces//upload//root//Chinese",fpath);
		ArrayList<String> Filepathst = ffd.findFilePath("E://Workspaces//upload//root//Chinese",fpath);
/*		for(String path : Filepaths){
			logger.info("需要传输文件的路径"+path);
		}*/
		for(String path : Filepathst){
			System.out.println("需要传输文件的路径2:"+path);
		}
	}
}

